// 主页布局页面
import React, {Component, Suspense, lazy} from 'react';
import {Switch, Route, Redirect} from 'react-router-dom';
import {Layout} from 'antd';
import Head from '../public-components/head/Head';
import LeftNav from '../public-components/leftNav/LeftNav';
import './Routers.scss';

import MainHome from '../pages/mainHome/MainHome';
import MaterialGroup from '../pages/materialGroup/MaterialGroup';
import CodeLibrary from '../pages/codeLibrary/CodeLibrary';
import SpecsLibrary from '../pages/specsLibrary/SpecsLibrary';
import GoodsLibrary from '../pages/goodsLibrary/GoodsLibrary';
import InstructionLibrary from '../pages/InstructionLibrary/InstructionLibrary';
import InstructionDetails from '../pages/InstructionLibrary/InstructionDetails';
import UserList from '../pages/userList/UserList';
import RoleList from '../pages/roleList/RoleList';
import JurisdictionList from '../pages/jurisdictionList/JurisdictionList';
import GeneratingGoods from '../pages/generatingGoods/GeneratingGoods';
import SupplierBefore from '../pages/supplierBefore/SupplierBefore';
import SelfBeforeOperated from '../pages/selfBeforeOperated/SelfBeforeOperated';
import SelfRearOperated from '../pages/selfRearOperated/SupplierBefore';
import ReturnReview from '../pages/returnReview/ReturnReview';
import Receiving from '../pages/receiving/Receiving';
import Refund from '../pages/refund/Refund';
import HistoryPurchase from '../pages/historyPurchase/HistoryPurchase';
import HistorySales from '../pages/historySales/HistorySales';
import UnpaidOrderLibrary from '../pages/unpaidOrderLibrary/UnpaidOrderLibrary';
import DataCenter from '../pages/dataCenter/DataCenter';
import Error from '../pages/error/ERROR';

const {Header, Sider, Content} = Layout;

class Routers extends Component {

  loginIntercept() {
    const islogin = localStorage.getItem('token') || false;
    let {history} = this.props;
    if (!islogin) {
      history.replace('/login');
    }
  }

  componentDidMount() {
    window._router = this.props.history;  // 用来axios的路由拦截跳转
    console.log(this.props.history);
    this.loginIntercept();
  }

  render() {
    return (
      <Layout className='resetLayout'>
        <Header>
          <Head/>
        </Header>
        <Layout>
          <Sider>
            <LeftNav/>
          </Sider>
          <Content>
            <Switch>
              <Route path='/' exact component={MainHome}/>
              <Route path='/materialgroup' exact component={MaterialGroup}/>
              <Route path='/codeLibrary' exact component={CodeLibrary}/>
              <Route path='/specsLibrary' exact component={SpecsLibrary}/>
              <Route path='/goodsLibrary' exact component={GoodsLibrary}/>
              <Route path='/instructionLibrary' exact component={InstructionLibrary}/>
              <Route path='/instructionDetails/:params' exact component={InstructionDetails}/>
              <Route path='/userList' exact component={UserList}/>
              <Route path='/roleList' exact component={RoleList}/>
              <Route path='/jurisdictionList' exact component={JurisdictionList}/>
              <Route path='/generatingGoods/:codes' exact component={GeneratingGoods}/>
              <Route path='/selfBeforeOperated' exact component={SelfBeforeOperated}/>
              <Route path='/supplierBefore' exact component={SupplierBefore}/>
              <Route path='/selfRearOperated' exact component={SelfRearOperated}/>
              <Route path='/returnReview' exact component={ReturnReview}/>
              <Route path='/receiving' exact component={Receiving}/>
              <Route path='/refund' exact component={Refund}/>
              <Route path='/historyPurchase' exact component={HistoryPurchase}/>
              <Route path='/historySales' exact component={HistorySales}/>
              <Route path='/unpaidOrderLibrary' exact component={UnpaidOrderLibrary}/>
              <Route path={'/dataCenter'} exact component={DataCenter}/>
              <Route component={Error}/>
              <Redirect to=''/>
            </Switch>
          </Content>
        </Layout>
      </Layout>
    );
  }
}

export default Routers;
